//
//  AgreementVC.swift
//  ShareUmbrella
//
//  Created by duanmingyang on 2017/9/21.
//  Copyright © 2017年 尧尚信息科技. All rights reserved.
//

import UIKit
import YSKit

class AgreementVC: YSBaseViewController,UIWebViewDelegate{
    let kScreenHeight = UIScreen.main.bounds.size.height
    let kScreenWidth = UIScreen.main.bounds.size.width
    var webView:UIWebView!
    
    override func setup() {
        super.setup()
    }
    
    /*
     *
     * 界面布局初始化
     */
    override func buildUI() {
        super.buildUI()
        self.title = I18n("VC.login.userargeement")
        
        self.edgesForExtendedLayout = UIRectEdge(rawValue: 0)
        
        self.initBackgourndViewColor()
        self.addWebView()
        
        
    }
    
    //
    override func buildRx() {
        super.buildRx()
    }
    
    //RGB
    func RGB(r:CGFloat,_ g:CGFloat,_ b:CGFloat) -> UIColor{
        return UIColor(red: (r)/255.0, green: (g)/255.0, blue: (b)/255.0, alpha: 1.0)
    }
    
    //初始化背景颜色
    func initBackgourndViewColor() {
        self.view.backgroundColor = self.RGB(r: 246, 246, 246)
    }
    
    //添加一个tableview
    func addWebView(){
        webView = UIWebView.init(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight-64))
        let path = Bundle.main.path(forResource: "userAgreement", ofType: "pdf")
        let urlStr = NSURL.fileURL(withPath: path!)
        webView.loadRequest(NSURLRequest(url: urlStr) as URLRequest)
        webView.backgroundColor = UIColor.white
        self.view.addSubview(webView)
    }
    
    //MARK UIWebView Delegate
    func webView(_ webView: UIWebView, didFailLoadWithError error: Error) {
        
        //加载失败时调用
    }
    func webViewDidFinishLoad(_ webView: UIWebView) {
        //加载完成时调用
        HUD.hide()
    }
    func webViewDidStartLoad(_ webView: UIWebView) {
        //开始加载时调用
        HUD.show()
    }
    
}
